package com.bkgy.modular.configureRules.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.SimulatedFriction2130Dto;
import com.bkgy.modular.configureRules.entity.SimulatedFriction2130;
import com.bkgy.modular.configureRules.mapper.SimulatedFriction2130Mapper;
import com.bkgy.modular.configureRules.service.SimulatedFriction2130Service;
import com.bkgy.sys.common.entity.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName SimulatedFriction2130Impl
 * @date 2023/4/20 11:27
 */
@Service
public class SimulatedFriction2130Impl extends ServiceImpl<SimulatedFriction2130Mapper, SimulatedFriction2130> implements SimulatedFriction2130Service {
    @Resource
    private SimulatedFriction2130Mapper mapper;

    @Override
    public ResultData querySimulatedFriction2130(JSONObject jsonObject) {
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");
        if (pageIndex == null || pageSize == null) {
            return ResultData.ResultDataFaultSelf("分页参数不能为空",-1);
        }

        PageHelper.startPage(pageIndex,pageSize);
        List<SimulatedFriction2130> selectList = mapper.selectList(null);
        PageInfo<SimulatedFriction2130> pageInfo = new PageInfo<>(selectList);
        return ResultData.ResultDataFaultSelf("操作成功",pageInfo);
    }

    @Override
    public ResultData updateSimulatedFriction2130(SimulatedFriction2130Dto dto) {
        Double id = dto.getId();
        if (id == null) {
            return ResultData.ResultDataFaultSelf("必传参数有误",-1);
        }
        String roll_type = dto.getRoll_type();
        Double oil_type = dto.getOil_type();
        Double coolant_mode = dto.getCoolant_mode();
        Double std = dto.getStd();
        Double myu0 = dto.getMyu0();
        Double myu1 = dto.getMyu1();
        Double myu2 = dto.getMyu2();
        Double myu3 = dto.getMyu3();
        Double myu4 = dto.getMyu4();
        Double myu5 = dto.getMyu5();

        LambdaQueryWrapper<SimulatedFriction2130> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SimulatedFriction2130::getId,id);

        SimulatedFriction2130 simulatedFriction2130 = mapper.selectOne(queryWrapper);
        if (simulatedFriction2130 != null) {
            simulatedFriction2130.setRoll_type(roll_type);
            simulatedFriction2130.setOil_type(oil_type);
            simulatedFriction2130.setCoolant_mode(coolant_mode);
            simulatedFriction2130.setStd(std);
            simulatedFriction2130.setMyu0(myu0);
            simulatedFriction2130.setMyu1(myu1);
            simulatedFriction2130.setMyu2(myu2);
            simulatedFriction2130.setMyu3(myu3);
            simulatedFriction2130.setMyu4(myu4);
            simulatedFriction2130.setMyu5(myu5);
            int flag = mapper.update(simulatedFriction2130, queryWrapper);
            if (flag == 1) {
                return ResultData.ResultDataFaultSelf("操作成功",1);
            }
        }
        return ResultData.ResultDataFaultSelf("操作失败",-1);
    }
}
